﻿namespace Sidvall.WorkItemManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class Schedule : global::Sidvall.WorkItemManager.UI.Entities.Core.BusinessBase, global::Sidvall.WorkItemManager.Data.ISchedule
    {
        #region Business Members

        #region DayEndTime

        private System.Nullable<System.DateTime> _DayEndTime = null;
        partial void OnBeforeDayEndTimePropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnBeforeDayEndTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnAfterDayEndTimePropertyChanged();
        public System.Nullable<System.DateTime> DayEndTime
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>>(Sidvall.Business.ValidationManager.GetValidDateTime(_DayEndTime));
                OnBeforeDayEndTimePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>>(value, _DayEndTime);
                OnBeforeDayEndTimePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("DayEndTime", eventData.Value, true, true, true);
                    OnAfterDayEndTimePropertyChanged();
                }
            }
        }

        #endregion
        #region DayFrequency

        private byte _DayFrequency = 1;
        partial void OnBeforeDayFrequencyPropertyGet(Sidvall.Business.PropertyEventData<byte> eventData);
        partial void OnBeforeDayFrequencyPropertyChanged(Sidvall.Business.PropertyChangeEventData<byte> eventData);
        partial void OnAfterDayFrequencyPropertyChanged();
        public byte DayFrequency
        {
            get
            {
                Sidvall.Business.PropertyEventData<byte> eventData = new Sidvall.Business.PropertyEventData<byte>(_DayFrequency);
                OnBeforeDayFrequencyPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<byte> eventData = new Sidvall.Business.PropertyChangeEventData<byte>(value, _DayFrequency);
                OnBeforeDayFrequencyPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("DayFrequency", eventData.Value, true, true, true);
                    OnAfterDayFrequencyPropertyChanged();
                }
            }
        }

        #endregion
        #region DayFrequencyTypeId

        private global::Sidvall.WorkItemManager.Workflow.Conditions.DayFrequencyType _DayFrequencyTypeId = global::Sidvall.WorkItemManager.Workflow.Conditions.DayFrequencyType.Onetime;
        partial void OnBeforeDayFrequencyTypeIdPropertyGet(Sidvall.Business.PropertyEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.DayFrequencyType> eventData);
        partial void OnBeforeDayFrequencyTypeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.DayFrequencyType> eventData);
        partial void OnAfterDayFrequencyTypeIdPropertyChanged();
        public global::Sidvall.WorkItemManager.Workflow.Conditions.DayFrequencyType DayFrequencyTypeId
        {
            get
            {
                Sidvall.Business.PropertyEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.DayFrequencyType> eventData = new Sidvall.Business.PropertyEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.DayFrequencyType>(_DayFrequencyTypeId);
                OnBeforeDayFrequencyTypeIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.DayFrequencyType> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.DayFrequencyType>(value, _DayFrequencyTypeId);
                OnBeforeDayFrequencyTypeIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("DayFrequencyTypeId", eventData.Value, true, true, true);
                    OnAfterDayFrequencyTypeIdPropertyChanged();
                }
            }
        }

        #endregion
        #region DayStartTime

        private System.Nullable<System.DateTime> _DayStartTime = null;
        partial void OnBeforeDayStartTimePropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnBeforeDayStartTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnAfterDayStartTimePropertyChanged();
        public System.Nullable<System.DateTime> DayStartTime
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>>(Sidvall.Business.ValidationManager.GetValidDateTime(_DayStartTime));
                OnBeforeDayStartTimePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>>(value, _DayStartTime);
                OnBeforeDayStartTimePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("DayStartTime", eventData.Value, true, true, true);
                    OnAfterDayStartTimePropertyChanged();
                }
            }
        }

        #endregion
        #region EndDate

        private System.Nullable<System.DateTime> _EndDate = null;
        partial void OnBeforeEndDatePropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnBeforeEndDatePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnAfterEndDatePropertyChanged();
        public System.Nullable<System.DateTime> EndDate
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<System.DateTime>>(Sidvall.Business.ValidationManager.GetValidDateTime(_EndDate));
                OnBeforeEndDatePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>>(value, _EndDate);
                OnBeforeEndDatePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("EndDate", eventData.Value, true, true, true);
                    OnAfterEndDatePropertyChanged();
                }
            }
        }

        #endregion
        #region Friday

        private bool _Friday = false;
        partial void OnBeforeFridayPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeFridayPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterFridayPropertyChanged();
        public bool Friday
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_Friday);
                OnBeforeFridayPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _Friday);
                OnBeforeFridayPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Friday", eventData.Value, true, true, true);
                    OnAfterFridayPropertyChanged();
                }
            }
        }

        #endregion
        #region Monday

        private bool _Monday = false;
        partial void OnBeforeMondayPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeMondayPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterMondayPropertyChanged();
        public bool Monday
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_Monday);
                OnBeforeMondayPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _Monday);
                OnBeforeMondayPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Monday", eventData.Value, true, true, true);
                    OnAfterMondayPropertyChanged();
                }
            }
        }

        #endregion
        #region MonthFrequency

        private byte _MonthFrequency = 1;
        partial void OnBeforeMonthFrequencyPropertyGet(Sidvall.Business.PropertyEventData<byte> eventData);
        partial void OnBeforeMonthFrequencyPropertyChanged(Sidvall.Business.PropertyChangeEventData<byte> eventData);
        partial void OnAfterMonthFrequencyPropertyChanged();
        public byte MonthFrequency
        {
            get
            {
                Sidvall.Business.PropertyEventData<byte> eventData = new Sidvall.Business.PropertyEventData<byte>(_MonthFrequency);
                OnBeforeMonthFrequencyPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<byte> eventData = new Sidvall.Business.PropertyChangeEventData<byte>(value, _MonthFrequency);
                OnBeforeMonthFrequencyPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("MonthFrequency", eventData.Value, true, true, true);
                    OnAfterMonthFrequencyPropertyChanged();
                }
            }
        }

        #endregion
        #region MonthFrequencyTypeId

        private global::Sidvall.WorkItemManager.Workflow.Conditions.MonthFrequencyType _MonthFrequencyTypeId = global::Sidvall.WorkItemManager.Workflow.Conditions.MonthFrequencyType.Day;
        partial void OnBeforeMonthFrequencyTypeIdPropertyGet(Sidvall.Business.PropertyEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.MonthFrequencyType> eventData);
        partial void OnBeforeMonthFrequencyTypeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.MonthFrequencyType> eventData);
        partial void OnAfterMonthFrequencyTypeIdPropertyChanged();
        public global::Sidvall.WorkItemManager.Workflow.Conditions.MonthFrequencyType MonthFrequencyTypeId
        {
            get
            {
                Sidvall.Business.PropertyEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.MonthFrequencyType> eventData = new Sidvall.Business.PropertyEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.MonthFrequencyType>(_MonthFrequencyTypeId);
                OnBeforeMonthFrequencyTypeIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.MonthFrequencyType> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.MonthFrequencyType>(value, _MonthFrequencyTypeId);
                OnBeforeMonthFrequencyTypeIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("MonthFrequencyTypeId", eventData.Value, true, true, true);
                    OnAfterMonthFrequencyTypeIdPropertyChanged();
                }
            }
        }

        #endregion
        #region Saturday

        private bool _Saturday = false;
        partial void OnBeforeSaturdayPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeSaturdayPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterSaturdayPropertyChanged();
        public bool Saturday
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_Saturday);
                OnBeforeSaturdayPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _Saturday);
                OnBeforeSaturdayPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Saturday", eventData.Value, true, true, true);
                    OnAfterSaturdayPropertyChanged();
                }
            }
        }

        #endregion
        #region ScheduleFrequency

        private byte _ScheduleFrequency = 1;
        partial void OnBeforeScheduleFrequencyPropertyGet(Sidvall.Business.PropertyEventData<byte> eventData);
        partial void OnBeforeScheduleFrequencyPropertyChanged(Sidvall.Business.PropertyChangeEventData<byte> eventData);
        partial void OnAfterScheduleFrequencyPropertyChanged();
        public byte ScheduleFrequency
        {
            get
            {
                Sidvall.Business.PropertyEventData<byte> eventData = new Sidvall.Business.PropertyEventData<byte>(_ScheduleFrequency);
                OnBeforeScheduleFrequencyPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<byte> eventData = new Sidvall.Business.PropertyChangeEventData<byte>(value, _ScheduleFrequency);
                OnBeforeScheduleFrequencyPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("ScheduleFrequency", eventData.Value, true, true, true);
                    OnAfterScheduleFrequencyPropertyChanged();
                }
            }
        }

        #endregion
        #region ScheduleFrequencyTypeId

        private global::Sidvall.WorkItemManager.Workflow.Conditions.ScheduleFrequencyType _ScheduleFrequencyTypeId = global::Sidvall.WorkItemManager.Workflow.Conditions.ScheduleFrequencyType.Onetime;
        partial void OnBeforeScheduleFrequencyTypeIdPropertyGet(Sidvall.Business.PropertyEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.ScheduleFrequencyType> eventData);
        partial void OnBeforeScheduleFrequencyTypeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.ScheduleFrequencyType> eventData);
        partial void OnAfterScheduleFrequencyTypeIdPropertyChanged();
        public global::Sidvall.WorkItemManager.Workflow.Conditions.ScheduleFrequencyType ScheduleFrequencyTypeId
        {
            get
            {
                Sidvall.Business.PropertyEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.ScheduleFrequencyType> eventData = new Sidvall.Business.PropertyEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.ScheduleFrequencyType>(_ScheduleFrequencyTypeId);
                OnBeforeScheduleFrequencyTypeIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.ScheduleFrequencyType> eventData = new Sidvall.Business.PropertyChangeEventData<global::Sidvall.WorkItemManager.Workflow.Conditions.ScheduleFrequencyType>(value, _ScheduleFrequencyTypeId);
                OnBeforeScheduleFrequencyTypeIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("ScheduleFrequencyTypeId", eventData.Value, true, true, true);
                    OnAfterScheduleFrequencyTypeIdPropertyChanged();
                }
            }
        }

        #endregion
        #region ScheduleId

        private System.Nullable<long> _ScheduleId = null;
        partial void OnBeforeScheduleIdPropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<long>> eventData);
        partial void OnBeforeScheduleIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData);
        partial void OnAfterScheduleIdPropertyChanged();
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public System.Nullable<long> ScheduleId
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<long>>(_ScheduleId);
                OnBeforeScheduleIdPropertyGet(eventData);
                return eventData.Value;
            }
            internal set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<long>>(value, _ScheduleId);
                OnBeforeScheduleIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("ScheduleId", eventData.Value, true, true, true);
                    OnAfterScheduleIdPropertyChanged();
                }
            }
        }

        #endregion
        #region StartTime

        private System.DateTime _StartTime = System.DateTime.UtcNow;
        partial void OnBeforeStartTimePropertyGet(Sidvall.Business.PropertyEventData<System.DateTime> eventData);
        partial void OnBeforeStartTimePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData);
        partial void OnAfterStartTimePropertyChanged();
        public System.DateTime StartTime
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.DateTime> eventData = new Sidvall.Business.PropertyEventData<System.DateTime>(Sidvall.Business.ValidationManager.GetValidDateTime(_StartTime));
                OnBeforeStartTimePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData = new Sidvall.Business.PropertyChangeEventData<System.DateTime>(value, _StartTime);
                OnBeforeStartTimePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("StartTime", eventData.Value, true, true, true);
                    OnAfterStartTimePropertyChanged();
                }
            }
        }

        #endregion
        #region Sunday

        private bool _Sunday = false;
        partial void OnBeforeSundayPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeSundayPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterSundayPropertyChanged();
        public bool Sunday
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_Sunday);
                OnBeforeSundayPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _Sunday);
                OnBeforeSundayPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Sunday", eventData.Value, true, true, true);
                    OnAfterSundayPropertyChanged();
                }
            }
        }

        #endregion
        #region Thursday

        private bool _Thursday = false;
        partial void OnBeforeThursdayPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeThursdayPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterThursdayPropertyChanged();
        public bool Thursday
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_Thursday);
                OnBeforeThursdayPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _Thursday);
                OnBeforeThursdayPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Thursday", eventData.Value, true, true, true);
                    OnAfterThursdayPropertyChanged();
                }
            }
        }

        #endregion
        #region Tuesday

        private bool _Tuesday = false;
        partial void OnBeforeTuesdayPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeTuesdayPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterTuesdayPropertyChanged();
        public bool Tuesday
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_Tuesday);
                OnBeforeTuesdayPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _Tuesday);
                OnBeforeTuesdayPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Tuesday", eventData.Value, true, true, true);
                    OnAfterTuesdayPropertyChanged();
                }
            }
        }

        #endregion
        #region Wednesday

        private bool _Wednesday = false;
        partial void OnBeforeWednesdayPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeWednesdayPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterWednesdayPropertyChanged();
        public bool Wednesday
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_Wednesday);
                OnBeforeWednesdayPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _Wednesday);
                OnBeforeWednesdayPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Wednesday", eventData.Value, true, true, true);
                    OnAfterWednesdayPropertyChanged();
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.ScheduleManager.GetKey(this);
            }
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.ScheduleManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.ScheduleManager.AcceptChanges(this);
        }

        #endregion
        #region Clone

        public Schedule Clone()
        {
            var copySettings = Sidvall.Data.CopySettings.Clone();
            return Copy(copySettings);
        }

        #endregion
        #region Copy

        public Schedule Copy()
        {
            return Copy(null);
        }
        public Schedule Copy(Sidvall.Data.CopySettings copySettings)
        {
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (!Sidvall.Data.DataRowContextManager.IsValid(this, copySettings.RowFilter))
                return null;
            var item = new Schedule();
            Import(item, this, copySettings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.WorkItemManager.Data.ISchedule item)
        {
            Import(item, null);
        }
        public void Import(global::Sidvall.WorkItemManager.Data.ISchedule item, Sidvall.Data.CopySettings copySettings)
        {
            Import(this, item, copySettings);
        }
        partial void OnAfterImport(Schedule destination, global::Sidvall.WorkItemManager.Data.ISchedule source, Sidvall.Data.CopySettings copySettings);
        private void Import(Schedule destination, global::Sidvall.WorkItemManager.Data.ISchedule source, Sidvall.Data.CopySettings copySettings)
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.ScheduleManager.Import(destination, source, copySettings);
            OnAfterImport(destination, source, copySettings);
        }
        partial void OnAfterImport(Schedule destination, Schedule source, Sidvall.Data.CopySettings copySettings);
        private void Import(Schedule destination, Schedule source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source as global::Sidvall.WorkItemManager.Data.ISchedule, copySettings);
            OnAfterImport(destination, source, copySettings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.ScheduleManager.ValidateAsync(this, context);
            await ValidateAsync(context);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync();
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.ScheduleManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.WorkItemManager.UI.SystemContextConfig.Current.EntityFacade.ScheduleManager.Initialize(this, settings);
        }

        #endregion
        
        #region ISchedule Members

        System.Nullable<System.DateTime> global::Sidvall.WorkItemManager.Data.ISchedule.DayEndTime
        {
            get
            {
                return this._DayEndTime;
            }
            set
            {
                this._DayEndTime = value;
            }
        }
        byte global::Sidvall.WorkItemManager.Data.ISchedule.DayFrequency
        {
            get
            {
                return this._DayFrequency;
            }
            set
            {
                this._DayFrequency = value;
            }
        }
        global::Sidvall.WorkItemManager.Workflow.Conditions.DayFrequencyType global::Sidvall.WorkItemManager.Data.ISchedule.DayFrequencyTypeId
        {
            get
            {
                return this._DayFrequencyTypeId;
            }
            set
            {
                this._DayFrequencyTypeId = value;
            }
        }
        System.Nullable<System.DateTime> global::Sidvall.WorkItemManager.Data.ISchedule.DayStartTime
        {
            get
            {
                return this._DayStartTime;
            }
            set
            {
                this._DayStartTime = value;
            }
        }
        System.Nullable<System.DateTime> global::Sidvall.WorkItemManager.Data.ISchedule.EndDate
        {
            get
            {
                return this._EndDate;
            }
            set
            {
                this._EndDate = value;
            }
        }
        bool global::Sidvall.WorkItemManager.Data.ISchedule.Friday
        {
            get
            {
                return this._Friday;
            }
            set
            {
                this._Friday = value;
            }
        }
        bool global::Sidvall.WorkItemManager.Data.ISchedule.Monday
        {
            get
            {
                return this._Monday;
            }
            set
            {
                this._Monday = value;
            }
        }
        byte global::Sidvall.WorkItemManager.Data.ISchedule.MonthFrequency
        {
            get
            {
                return this._MonthFrequency;
            }
            set
            {
                this._MonthFrequency = value;
            }
        }
        global::Sidvall.WorkItemManager.Workflow.Conditions.MonthFrequencyType global::Sidvall.WorkItemManager.Data.ISchedule.MonthFrequencyTypeId
        {
            get
            {
                return this._MonthFrequencyTypeId;
            }
            set
            {
                this._MonthFrequencyTypeId = value;
            }
        }
        bool global::Sidvall.WorkItemManager.Data.ISchedule.Saturday
        {
            get
            {
                return this._Saturday;
            }
            set
            {
                this._Saturday = value;
            }
        }
        byte global::Sidvall.WorkItemManager.Data.ISchedule.ScheduleFrequency
        {
            get
            {
                return this._ScheduleFrequency;
            }
            set
            {
                this._ScheduleFrequency = value;
            }
        }
        global::Sidvall.WorkItemManager.Workflow.Conditions.ScheduleFrequencyType global::Sidvall.WorkItemManager.Data.ISchedule.ScheduleFrequencyTypeId
        {
            get
            {
                return this._ScheduleFrequencyTypeId;
            }
            set
            {
                this._ScheduleFrequencyTypeId = value;
            }
        }
        System.Nullable<long> global::Sidvall.WorkItemManager.Data.ISchedule.ScheduleId
        {
            get
            {
                return this._ScheduleId;
            }
            set
            {
                this._ScheduleId = value;
            }
        }
        System.DateTime global::Sidvall.WorkItemManager.Data.ISchedule.StartTime
        {
            get
            {
                return this._StartTime;
            }
            set
            {
                this._StartTime = value;
            }
        }
        bool global::Sidvall.WorkItemManager.Data.ISchedule.Sunday
        {
            get
            {
                return this._Sunday;
            }
            set
            {
                this._Sunday = value;
            }
        }
        bool global::Sidvall.WorkItemManager.Data.ISchedule.Thursday
        {
            get
            {
                return this._Thursday;
            }
            set
            {
                this._Thursday = value;
            }
        }
        bool global::Sidvall.WorkItemManager.Data.ISchedule.Tuesday
        {
            get
            {
                return this._Tuesday;
            }
            set
            {
                this._Tuesday = value;
            }
        }
        bool global::Sidvall.WorkItemManager.Data.ISchedule.Wednesday
        {
            get
            {
                return this._Wednesday;
            }
            set
            {
                this._Wednesday = value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public Schedule()
        {
        }

        public Schedule(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}